package com.example.printservice.result;

import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Result<T> {
    private ResultEnum info;
    private Integer code;
    private String msg;
    private T data;



    public Result(ResultEnum resultEnum){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public Result(ResultEnum resultEnum, T data){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
        this.data = data;
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    //成功时引用

    public static <T> Result<T> success(){
        return success(null);
    }


    public static <T> Result<T> success(T data){
        return new Result<>(ResultEnum.SUCCESS, data);
    }

    // 自定义结果
    public static <T> Result<T> custom(Integer code,String msg,T data){
        return new Result<>(code, msg, data);
    }

    //失败时引用

    public static <T> Result<T> error(ResultEnum resultEnum){
        return new Result<>(resultEnum);
    }
}

